<?php 
namespace app\dboard\logic;
use think\Db;
use think\facade\Session;
class Login extends Base
{

	function __construct()
	{
	}

	public function login($param)
	{
		$password = get_admin_pwd($param['password']);
		$admin_user = Db::name('admin_user')->where(['user_name'=>$param['user_name'],'password'=>$password])->find();
		if (!$admin_user) {
			$this->error_data['ErrorMsg'] = "账号或密码不存在";
			return $this->error_data;
		}
		if ($admin_user['status']!=1) {
			$this->error_data['ErrorMsg'] = "账号被禁用";
			return $this->error_data;
		}
		$data['login_times'] = intval($admin_user['login_times'])+1;
		$data['login_time'] = now_time();
		$data['update_time'] = now_time();
		$data['update_ip'] = request()->ip();
		$update = Db::name('admin_user')->where('id',$admin_user['id'])->update($data);
		if (!$update) {
			$this->error_data['ErrorMsg'] = "登陆失败";
			return $this->error_data;
		}
        Session::set('AccountInfo',['id'=>$admin_user['id'],'group_id'=>$admin_user['group_id'],'user_name'=>$admin_user['user_name'],'port_id'=>$admin_user['port_id'],'port_name'=>$admin_user['port_name'],'tel'=>$admin_user['tel']]);
        $redirect = '';
        switch ($admin_user['group_id']) {
        	case 1:
        		$redirect = '/dashboard/operator/console';
        		break;
        	case 2:
        		$redirect = '/dashboard/operator/console';
        		break;
        	case 3:
        		$redirect = '/dashboard/index/crewman_task';
        		break;
        	case 4:
        		$redirect = '/dashboard/index/freight_order_task';
        		break;
        	
        	default:break;
        }
        $this->res_data['Data'] = $redirect;
        $this->res_data['ErrorMsg'] = '登录成功';
        $this->res_data['ErrorCode'] = 1;
        return $this->printResult($this->res_data);
	}
}

 ?>
